package com.cskaoyan.controller;

import com.cskaoyan.bean.MarketIssue;
import com.cskaoyan.bean.bo.AdminIssueCreateBO;
import com.cskaoyan.bean.bo.AdminIssueListBO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.AdminIssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 通用问题模块
 * \* User: 余雨健
 * \* Date: 2022/10/13
 * \* Time: 17:30
 **/
@RestController
@RequestMapping("admin/issue")
public class AdminIssueController {

    @Autowired
    AdminIssueService adminIssueService;

    /**
     *@通用问题的显示
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:21
     */
    @RequestMapping("list")
    public BaseRespVo<CommonData> list(AdminIssueListBO adminIssueListBO){
        CommonData<MarketIssue> data = adminIssueService.selectIssueList(adminIssueListBO);
        return BaseRespVo.ok(data,"成功");
    }

    /**
     *@通用问题的创建
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:21
     */
    @PostMapping("create")
    public BaseRespVo<MarketIssue> create(@RequestBody AdminIssueCreateBO adminIssueCreateBO){
        MarketIssue issue = adminIssueService.createIssue(adminIssueCreateBO);
        return BaseRespVo.ok(issue,"成功");
    }

    /**
     *@通用问题的修改
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:21
     */
    @PostMapping("update")
    public BaseRespVo<MarketIssue> update(@RequestBody MarketIssue marketIssue) throws ParseException {
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String Date = formatter.format(date);
        java.util.Date date1 = formatter.parse(Date);
        marketIssue.setUpdateTime(date1);
        adminIssueService.updateIssue(marketIssue);
        return BaseRespVo.ok(marketIssue,"成功");
    }

    /**
     *@通用问题的删除
     *@author yuyujian
     *@Date 2022/10/13
     *@Time 22:21
     */
    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody MarketIssue marketIssue){
        adminIssueService.deleteIssue(marketIssue);
        return BaseRespVo.ok(null,"成功");
    }
}
